import JSEncrypt from "jsencrypt/bin/jsencrypt";

// 生成非对称加密公钥和私钥
const publicKey =
  "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMcdrhrJj1OPyp6lbWmQbqnMU/aGrdkQ\n" +
  "rVxN9xCKx+9AO1NssdvVur1tIHnkoh9NLy0POwREGdlo093+8VNTLvsCAwEAAQ==";

const privateKey =
  "MIIBOwIBAAJBAMcdrhrJj1OPyp6lbWmQbqnMU/aGrdkQrVxN9xCKx+9AO1NssdvVur1tIHnkoh9NLy0POwREGdlo093+8VNTLvsCAwEAAQJACYmfNu+qSqzIkXDUtnArEApJiBvk/lDElqp++yJERKF2KeEOkmCxSCcuFRugaUZSX/K414b5ae2wYGmylBZ5gQIhANi1+dRvczVmkkrqDbOOwmZyhmTt31vorawCezmrNZ/PAiEA6zcWDrmwP7mW/54u8lcaqnfV4o9+PTbfHETnKNULfRUCIQCKmaBmIL2jaq2n4hfPPj/Q+/A+fvB6vM7Ok2uyT3DlewIhALtiTS45/BEoVwUZDal+fv3jLf+p9RXrSt8IfWdoIhjpAiBQYOeS/MDjEf9Oz748v5am0bKxhyCufd6d/GZ50mHTUQ==";

//加密
export function encrypt(text) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey);
  return encryptor.encrypt(text);
}

//解密
export function decrypt(text) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey);
  return encryptor.decrypt(text);
}
